
var wallet = require('../../wallet.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
        textList:[1,2,3,4,5,6],
        arrData:[],
        time:0,
        val:'',
        setpwd:{},
        pswd:'',
        keyBoardF:true
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   /* var writeMessage = '123456'
    var l = util.hashPersonalMessage(Buffer.from(writeMessage, 'hex'))
    console.log(l.toString('hex'))
    console.log(util.addHexPrefix(l.toString('hex')));
    var pswd = CryptoJs.MD5('123567').toString();
    console.log(pswd)*/
  },
  shuruEvent:function(ev){
    //console.log(ev.detail.value.length);
    switch(ev.detail.value.length){
      case 0:
        this.setData({
          arrData: []
        })
      break;
      case 1:
      this.setData({
        arrData:[0]
      })
      break;
      case 2:
        this.setData({
          arrData: [0,1]
        })
      break;
      case 3:
      this.setData({
        arrData: [0, 1,2]
      })
      break;
      case 4:
        this.setData({
          arrData: [0, 1,2,3]
        })
      break;
      case 5:
        this.setData({
          arrData: [0, 1,2,3,4]
        })
      break;
      case 6:
        this.setData({
          arrData: [0, 1,2,3,4,5]
        })
        this.huoquEvent(ev)
      break;
      default:
      break;
    }
   
    //console.log(this.data.arrData);
  },
  huoquEvent:function(e){
    let val = e.detail.value;
    if(/^\w{6}$/i.test(val)){
       // console.log('校验通过')
        if (this.data.time == 1) {
          this.setData({
            time: 0,
            arrData:[]
          })
        //  console.log(this.data.pswd)
        //  console.log(val)
          if(this.data.pswd==val){
              //console.log(val.toString('hex'))
             /*var mima =  util.hashPersonalMessage(Buffer.from(val, 'hex'));//密码明文加密
             var pswd =  util.addHexPrefix(mima.toString('hex'))*/
             //console.log(val)
             //var pswd = CryptoJs.MD5(val).toString();
            var pswd = wallet.MD5jiami(val)
             //console.log(pswd)
             wx.setStorageSync('pswd', pswd)
             wx.navigateTo({
                url: '../leadHelp/leadHelp'
             })
             this.setData({
               keyBoardF:false
             })
          }else{
            wx.showToast({
              title: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].notConsistent : wx.T.locales['en'].notConsistent,
              icon: 'none',
              duration: 2000
            })
          }
        } else {
          this.setData({
            time: 1,
            arrData:[],
            pswd:val
          })
        } 
    }
    // else{
    //   wx.showToast({
    //     title: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].NorLorU : wx.T.locales['en'].NorLorU,
    //     icon: 'none',
    //     duration: 2000
    //   })
    // }
 
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      setpwd: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'] : wx.T.locales['en']

    })
    wx.setNavigationBarTitle({
      title: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].setpswd : wx.T.locales['en'].setpswd
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})